<template>
  <el-table v-loading="listLoading" :data="list" size="small" highlight-current-row height="calc((100% - 70px) * 0.4)" style="min-height: 200px; margin-top: 15px" v-if="configId">
    <el-table-column label="序号" type="index" width="50" />
    <el-table-column label="验收标准" prop="content" show-overflow-tooltip min-width="200">
      <span slot-scope="{ row }" :style="{ color: ['2', '3'].includes(row.seriousLevel) ? 'red' : '' }">{{ row.seriousLevel == '3' ? '*' : '' }} {{ row.content }}</span>
    </el-table-column>
    <el-table-column label="模块" align="center">
      <dict-tag slot-scope="{ row }" :options="dict.type.cq_data_modules" :value="row.modules" />
    </el-table-column>
    <el-table-column label="分块" align="center">
      <dict-tag slot-scope="{ row }" :options="dict.type.cq_data_blocks" :value="row.blocks" />
    </el-table-column>
    <el-table-column label="部位" align="center">
      <dict-tag slot-scope="{ row }" :options="dict.type.cq_data_positions" :value="row.positions" />
    </el-table-column>
    <el-table-column label="数据归集" show-overflow-tooltip align="center">
      <dict-tag slot-scope="{ row }" :options="dict.type.cq_data_collections" :value="row.dataCollections" />
    </el-table-column>
    <!-- <el-table-column label="排序" prop="seq" align="center" width="50" />
    <el-table-column align="center" width="120">
      <template slot="header">
        <el-button size="mini" type="primary" icon="el-icon-plus" @click="$refs.EditStandard.open({ configId })" v-hasPermi="['system:post:add']">新增</el-button>
      </template>
      <template slot-scope="{ row }">
        <el-button size="mini" type="text" icon="el-icon-edit" @click="$refs.EditStandard.open(row)" v-hasPermi="['system:post:edit']">修改</el-button>
        <el-button size="mini" type="text" icon="el-icon-delete" :loading="row.removeLoading" @click="btnRemoveItem(row)" v-hasPermi="['system:post:remove']">删除</el-button>
      </template>
    </el-table-column> -->
  </el-table>

  <!-- <EditStandard ref="EditStandard" v-model="showEditStandard" @ok="getList" /> -->
</template>
<script>
// 工程质量-楼栋工序配置-验收标准列表
// import { debounce } from '@/utils'
import { listCheckConfigStandard, delCheckConfigStandard } from '@/api/qualityManage/cq'
// import EditStandard from './EditCheckConfigStandard'
export default {
  name: 'CheckConfigStandardList',
  // components: { EditStandard },
  dicts: ['cq_data_modules', 'cq_data_blocks', 'cq_data_positions', 'cq_data_collections'],
  data() {
    return {
      configId: '',
      listLoading: false,
      list: [],
      showEditStandard: false
    }
  },
  // created() {
  //   this.btnRemoveItem = debounce(this.removeItem, 1e3, true)
  // },
  methods: {
    reset() {
      this.configId = ''
      this.list = []
    },
    open(item = {}) {
      if (!item.configId) return this.reset()
      this.configId = item.configId

      const list = item.standards || []
      if (list.length) return (this.list = list)

      this.getList()
    },
    async getList() {
      const { configId } = this
      if (!configId) return this.reset()

      this.listLoading = true
      const res = await listCheckConfigStandard({ id: configId }).catch(() => false)
      this.listLoading = false
      if (res === false) return

      const data = res.data?.standards || []
      data.map(i => (i.removeLoading = false))
      this.list = data
    },
    async removeItem(item) {
      if (item.removeLoading) return
      const res1 = await this.$confirm(`确认删除数据项：${item.content}?`, '警告', { type: 'warning' }).catch(() => false)
      if (res1 !== 'confirm') return

      // TODO 未验证接口
      item.removeLoading = true
      const res = await delCheckConfigStandard(item.standardId).catch(() => false)
      item.removeLoading = false
      if (res === false) return

      this.msgSuccess('删除成功')
      this.getList()
    }
  }
}
</script>
